/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package onlinestore.user;
import java.sql.*;
/**
 *
 * @author Li
 */
public class user {
    private String username = "test";
    private String password = "test";
    private String email = "test";
    private Boolean isBuyer = true;

    public String finUser(String s)
            {
            System.out.println("in method finUser s is equal to = " +s );
    
        try {
            //LOAD THE DRIVER
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            //CREATE URL STRING
            String URL = "jdbc:mysql://127.0.0.1:3306/onlinestore?user=root&password=1989";
            //CONNECTING TO SQL
            Connection c = DriverManager.getConnection(URL);
            //CONNECTED
            Statement st = c.createStatement();
            //COMMAND
            ResultSet rs = st.executeQuery("SELECT * FROM `onlinestore`.`user` Where username = '"+s+"'");

            while(rs.next()){
                setUsername(rs.getString("username"));
                System.out.println("username : "+getUsername());
                setPassword(rs.getString("password"));
                System.out.println("password : "+getPassword());
            }
            c.close();

        } catch (Exception e) {
            System.err.println("ERROR: " + e);
        }
        return getUsername();
    }

    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }

    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }
}
